package com.atugui.test;

import com.atguigu.bean.Boss;
import com.atguigu.bean.Car;
import com.atguigu.config.MainConfigOfAutowired;
import com.atguigu.config.MainConfigOfLifeCycle;
import com.atguigu.dao.BookDao;
import com.atguigu.service.BookService;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;


public class IOCTest_Autowired {

    @Test
    public void test01() {
        //1.创建IOC容器
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfigOfAutowired.class);
        System.out.println("容器创建完成......");


        BookService bookService = applicationContext.getBean(BookService.class);
        bookService.print();

        //这里测试@Bean和@Repository同时注入一个类型,会报错。
//        BookDao bookDao = applicationContext.getBean(BookDao.class);
//        System.out.println(bookDao);

        Boss boss = applicationContext.getBean(Boss.class);
        System.out.println(boss);

        Car car = applicationContext.getBean(Car.class);
        System.out.println(car);

        //关闭容器
        applicationContext.close();

    }

}
